package avicit.bdp.dcs.plugin.api;

import avicit.bdp.common.dto.api.APIHttpDefinition;
import avicit.bdp.dcs.plugin.BaseDataxParam;
import avicit.bdp.dcs.plugin.DataxConstants;
import avicit.bdp.dcs.plugin.DataxJsonInterface;
import avicit.bdp.dcs.plugin.api.param.ApiDataxParam;
import cn.hutool.core.bean.BeanUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：liyb
 * @邮箱：liyb@avic-digital.com
 * @创建时间： 2020-08-01 11:39
 * @类说明：
 * @修改记录：
 */
public class ApiDataxJson implements DataxJsonInterface {

    /**
     * 获取Reader插件名称
     *
     * @return
     */
    @Override
    public String getReaderName() {
        return DataxConstants.HTTP_READER;
    }

    /**
     * 获取Writer插件名称
     *
     * @return
     */
    @Override
    public String getWriterName() {
        return null;
    }

    /**
     * 构建Reader json
     * @return
     */
    @Override
    public Map<String, Object> buildReader(BaseDataxParam param) {
        Map<String, Object> readerObj = new HashMap<>(4);
        readerObj.put(DataxConstants.NAME, getReaderName());

        ApiDataxParam dataxParam = (ApiDataxParam) param;

        APIHttpDefinition apiHttpDefinition = dataxParam.getApiHttpDefinition();
        Map<String, Object> parameterObj = BeanUtil.beanToMap(apiHttpDefinition);

        parameterObj.put(DataxConstants.RDBMS_COLUMN, dataxParam.getColumnList());

        readerObj.put(DataxConstants.PARAMETER, parameterObj);
        return readerObj;
    }

    /**
     * 构建Writer json
     * @return
     */
    @Override
    public Map<String, Object> buildWriter(BaseDataxParam param) {

        return null;
    }

}
